home *** CD-ROM | disk | FTP | other *** search
/ Deadlock 6 / Deadlock 6.adf / FileLoaderSource.s < prev   
Text File  |  1992-09-02  |  6KB  |  315 lines

  1.     Opt    C-
  2. * AmigaDos Fileloader V2.0 - Written by Motive/Dimension-X
  3. * for inclusion in Deadlock Issue 6
  4. *
  5. * This boot-block code, will relocate itself to a high-part of memory 
  6. * and then load the file that has been specified. 
  7. * This Routine is no-where near as effective as it could be but it
  8. * does the job, below are a list of functions which 
  9. *----------------------------------/X\acros----------------------------------
  10.  
  11.  
  12. Highmemory = $7f000        ; Address to relocate to
  13.  
  14. td_motor_off    macro
  15.     move.w  #$0009,$1c(a1)
  16.     move.l  #$00000000,$24(a1)
  17.     move.l    4.w,a6
  18.     jsr     -$1c8(a6)
  19.     endm
  20.  
  21. td_read    macro
  22.     move.l  #\1,$28(a1)            ;address to read to
  23.     move.l  #\2*512,$2c(a1)            ;block offset
  24.     move.l  #\3*512,$24(a1)            ;no of blocks
  25.     move.l    4.w,a6
  26.     jsr     -$1c8(a6)
  27.     endm
  28.  
  29. bootdos    macro
  30.     dc.b    "DOS",0
  31.     dc.l    0,$370
  32.     endm
  33. bootndos    macro
  34.     dc.b    "NDOS"
  35.     dc.l    0,$370
  36.     endm
  37.  
  38. *----------------------------------/X\acros----------------------------------
  39.  
  40. bootblockstart:
  41.     bootdos
  42.     lea    diskio_addr(pc),a0    ;store trackdisk io structure
  43.     move.l    a1,(a0)    
  44.  
  45.     lea    $dff000,a5
  46.      move.w    #$180,$96(a5)        ;disable copper&bitplane dma
  47.     move.w    #$0,$180(a5)        
  48.  
  49.     ;lea    $7fff0,a7
  50.  
  51.     lea    RelocateStart(pc),a0    
  52.     lea    HighMemory,a1        ;high-memory
  53.  
  54.     move.w    #Bootsize-1,d0        ;size of code to copy
  55. copyloop:
  56.     move.b    (a0)+,(a1)+
  57.     dbra    d0,copyloop
  58.     
  59.     jmp    HighMemory
  60.     
  61.  
  62. RelocateStart:
  63.     lea    filename(pc),a0        ;filename
  64.     lea    $40000,a3        ;address to load to
  65.     bsr    load_file
  66.     tst.l    d0
  67.     bmi    file_doesnt_exist    ;
  68.  
  69.  
  70. ;----------------------------------------
  71. ;call your code from here!
  72.     lea    $40020,a0
  73.     move.l    a0,$80.w
  74.     trap    #0
  75.     
  76.  
  77.  
  78. ;----------------------------------------
  79.     
  80. file_doesnt_exist:
  81.     moveq.l    #-1,d0            ;this should never occur
  82.     rts                ;unless you have forgot to put you
  83.                     ;files on disk
  84.  
  85.  
  86.  
  87.  
  88.  
  89. filename_address    dc.l    0
  90. load_file:    
  91.     bsr    calc_hash
  92.     move.l    d0,d1
  93.     move.l    d0,-(a7)
  94. get_root_block:
  95.     move.l    diskio_addr(pc),a1    ;retrieve io request structure
  96.  
  97.     lea    buffer(pc),a0
  98.     move.l  a0,$28(a1)
  99.     move.l  #880*512,$2c(a1)    ;block 880 (track 40)
  100.     move.l  #1*512,$24(a1)        ;1 block to read
  101.     move.l    4.w,a6
  102.     jsr     -$1c8(a6)        ;do diskio request
  103.     
  104.     move.l    diskio_addr(pc),a1
  105.     tst.b    32(a1)
  106.     beq.s    no_root_error
  107.     bra.s    get_root_block        ;continous loop !?!?
  108. no_root_error:
  109.     move.l    (a7)+,d0
  110.     lea    buffer+(6*4)(pc),a0    ;find start of hash table
  111.     move.l    (a0,d0.l),d0        ;get pointer to file header block
  112.     tst.l    d0            ;if zero then no such file!
  113.     beq    no_file            
  114.     move.l    d0,d2
  115. get_fh_block
  116.     moveq.l    #1,d1
  117.     lea    buffer(pc),a0        ;address to read fh block
  118.     bsr    read_blocks        ;read file header block
  119.     tst.b    d0
  120.     beq.s    no_fh_error        ;errro attempting to read block
  121.     
  122.     move.l    d2,d0
  123.     bra.s    get_fh_block
  124. no_fh_error:
  125.  
  126.  
  127. check_file_header:
  128.     lea    buffer(pc),a0
  129.     add.l    #(108*4)+1,a0        ;locate filename in fh block
  130.     move.l    filename_address(pc),a5
  131.     move.l    a5,a2    ;filename
  132. check_filename_loop:            ;compare filename & filename in fh block
  133.     move.b    (a0)+,d2
  134.     bsr    upper            ;convert to upper case
  135.     move.b    d2,d3
  136.     move.b    (a2)+,d2
  137.     bsr    upper            ;convert to upper case
  138.     move.b    d2,d4
  139.     tst.b    d4
  140.     beq    name_complete
  141.     cmp.b    d3,d4
  142.     bne.s    wrong_filename
  143.     bra.s    check_filename_loop
  144. wrong_filename:                ;if wrong file then try next
  145.     lea    buffer(pc),a0        ;file in the hash chain
  146.  
  147.     move.l    124*4(a0),d0        ;next in hash chain
  148.     move.l    #1,d1            ;block_len
  149.     tst.l    d0            ;if zero then end of hash chain
  150.     beq.s    no_file    
  151.     move.l    d0,d2
  152. get_fh_next:
  153.     lea    buffer(pc),a0
  154.     bsr    read_blocks        ;read next fh in chain
  155.     tst.b    d0
  156.     beq.s    no_fhchain_error
  157.     
  158.     move.l    d2,d0
  159.     
  160.     bra.s    get_fh_next
  161.  
  162. no_fhchain_error:
  163.  
  164.     bra.s    check_file_header
  165. name_complete:
  166.  
  167. load_data_loop:
  168.     lea    buffer(pc),a0    ;pointer to data-block
  169.     move.l    4*4(a0),d0
  170.     tst.l    d0
  171.     beq.s    file_end    ;if zero then no more blocks to read
  172.     move.l    d0,d2
  173. get_data_block
  174.     moveq.l    #1,d1
  175.     lea    buffer(pc),a0
  176.     bsr    read_blocks    ;read data block
  177.     tst.b    d0
  178.     beq.s    no_data_error
  179.     
  180.     
  181.     move.l    d2,d0
  182.     bra.s    get_data_block
  183. no_data_error
  184.  
  185.     bsr    check_checksum    
  186.     tst.l    d0
  187.     bpl    block_ok
  188.  
  189. reset_drive:    
  190.     bra    load_data_loop
  191.     
  192.  
  193. block_ok:
  194.     lea    buffer(pc),a0
  195.     move.l    load_address(pc),a2
  196.     move.l    3*4(a0),d0    ;size of data block
  197.     lea    6*4(a0),a0    ;pointer to start of data
  198. copy_data_loop:
  199.     move.b    (a0)+,(a2)+    ;copy block read in to load-address
  200.     subq.l    #1,d0
  201.     bne.s    copy_data_loop
  202.  
  203.     lea    load_address(pc),a0
  204.     move.l    a2,(a0)        ;store load-address
  205.     bra.s    load_data_loop    
  206. file_end:
  207.     td_motor_off
  208.     moveq.l    #1,d0        ;no error
  209.     rts
  210. no_file:
  211.     
  212.     td_motor_off
  213.     moveq.l    #-1,d0        ;file error
  214.     rts
  215.  
  216. upper:    cmp.b    #'a',d2
  217.     blt.s    not_lower
  218.     cmp.b    #'z',d2
  219.     bgt.s    not_lower
  220.     sub.b    #$20,d2        
  221. not_lower
  222.     rts
  223.  
  224. calc_hash:
  225.     movem.l    d0-d7/a0-a6,-(a7)
  226.     lea    load_address(pc),a2
  227.     move.l    a3,(a2)
  228.     move.l    a0,a1
  229.     moveq.l    #0,d0        ;name length
  230.     move.l    a0,a5
  231.     lea    filename_address(pc),a4
  232.     move.l    a5,(a4)
  233.  
  234. next_character:
  235.     tst.b    (a1)+
  236.     bne.s    next_character
  237.     sub.l    a0,a1
  238.     subq.l    #1,a1
  239.     move.l    a1,d0
  240.     move.l    a0,a1
  241.     move.l    d0,d1
  242.     subq.l    #1,d1
  243. hash_char
  244.     moveq.l    #0,d2
  245.     
  246.     mulu    #13,d0
  247.     move.b    (a0)+,d2    ;next character
  248.     bsr.s    upper        ;convert to upper-case
  249.     add.w    d2,d0
  250.     and.w    #$7ff,d0
  251.     dbra    d1,hash_char
  252.     divu    #72,d0
  253.     swap    d0        ;remainder (modulo)
  254.     lsl.w    #2,d0
  255.     and.l    #$ffff,d0
  256.     move.l    d0,(a7)
  257.     movem.l    (a7)+,d0-d7/a0-a6
  258.     rts    
  259.  
  260.  
  261. load_address    dc.l    0    
  262. ;    td_motor_off
  263. ;    td_read    address,sector_offset,sector_len
  264.  
  265. read_blocks:
  266.     movem.l    d0-d7/a0-a6,-(a7)
  267.     move.l    diskio_addr(pc),a1    ;retrieve io request structure
  268.     move.l  a0,$28(a1)        ;address to read to
  269.     mulu    #512,d0            ;block offset * 512
  270.     mulu    #512,d1            ;block length * 512
  271.     move.l  d0,$2c(a1)        
  272.     move.l     d1,$24(a1)
  273.     move.l    4.w,a6
  274.     jsr     -$1c8(a6)        ;Do DiskIO
  275.     move.l    diskio_addr(pc),a1
  276.     moveq.l    #0,d0
  277.     move.b    32(a1),d0        ;get possible error flags (if any)
  278.     move.l    d0,(a7)
  279.     movem.l    (a7)+,d0-d7/a0-a6
  280.     rts
  281.  
  282. Check_checksum:
  283.     movem.l    d1-d7/a0-a6,-(a7)
  284.     Lea    Buffer,a0
  285.     Move.l    20(a0),d1
  286.     Move.l    #0,20(a0)        
  287.     MOveq.l    #0,d0
  288.     Move.w    #$7f,d0
  289. .Checksum_loop:
  290.     Add.l    (a0)+,d1
  291.     Dbra    d0,.Checksum_loop
  292.     Tst.l    d1
  293.     Beq.s    .Checksum_Ok
  294. .Checksum_error:
  295.     Moveq.l    #-1,d0
  296.     Movem.l    (a7)+,d1-d7/a0-a6
  297.     Rts
  298. .Checksum_Ok:
  299.     Moveq.l    #1,d0    ;No_error
  300.     Movem.l    (a7)+,d1-d7/a0-a6
  301.     rts
  302.  
  303.     
  304.  
  305. diskio_addr    dc.l    0
  306.  
  307. filename:    dc.b    "loader.exe",0
  308.  
  309. buffer:                    ;start address to load blocks to
  310. bootsize=*-RelocateStart        ;Length of Boot Code
  311.  
  312.     End
  313.